package com.lizemin.spring.util;

/**
 * @author lzm
 * @date 2025/4/30 20:56
 * @description 类型转换工具
 */
public class ConvertionService {

    @SuppressWarnings("unchecked")
    public static <T> T convert(Object source, Class<T> target) {
        if (source == null) {
            return null;
        }
        if (target == null) {
            throw new RuntimeException("目标class不能为空");
        }
        if (Integer.class.equals(target)) {
            return (T) Integer.valueOf(source.toString());
        }
        if (Long.class.equals(target)) {
            return (T) Long.valueOf(source.toString());
        }
        return null;
    }
}
